/**
 * 把Ajax封装起来
 */
// if(window.$==null||window.$==undefined){
// 	window.$={};
// }
/**
 * @param {Object} url 请求地址
 * @param {Object} requestMethod 请求方式
 * @param {Object} json 请求时携带的json
 * @param {Object} callback 数据响应后的回调方法
 */
window.rest = function(url, requestMethod, json, callback) {
	//把请求方式统一转化为大写
	requestMethod = requestMethod.toUpperCase();
	let xmlHttp = null;
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			callback(JSON.parse(xmlHttp.responseText));
		}
	};
	xmlHttp.open(requestMethod, url, true);
	let token = localStorage.getItem("token");
	xmlHttp.setRequestHeader("token", token);

	if (requestMethod == "GET") {
		xmlHttp.send();
	} else {
		xmlHttp.setRequestHeader("Content-Type", "application/json");
		xmlHttp.send(JSON.stringify(json));
	}
}